package app.texas.com.devilfishhouse.View.Fragment.houuseList;

import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.map.MapView;
import com.universal_library.fragment.BaseFragment;

import app.texas.com.devilfishhouse.R;
import app.texas.com.devilfishhouse.myUtils.WLogger;
import app.texas.com.devilfishhouse.ui.SimpleBackActivity;
import app.texas.com.devilfishhouse.ui.SimpleBackPage;
import app.texas.com.devilfishhouse.ui.UiHelper;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by solin on 2018/7/21.
 * 房产详情页
 */

public class HouseInfoFragment extends BaseFragment implements View.OnClickListener {
    private int[] pics = new int[]{R.mipmap.house_test, R.mipmap.house_test, R.mipmap.house_test};

    @BindView(R.id.iv_back)
    ImageView iv_back;

    @BindView(R.id.tv_title_text)
    TextView tv_title_text;

    @BindView(R.id.tv_plan)
    TextView tv_plan;
    //图片简介
    @BindView(R.id.view_pager)
    ViewPager view_pager;
    //房屋价格
    @BindView(R.id.tv_housePrice)
    TextView tv_housePrice;
    //房屋状态
    @BindView(R.id.tv_house_status)
    TextView tv_house_status;
    //房屋地址
    @BindView(R.id.tv_houseAddress)
    TextView tv_houseAddress;
    //电话
    @BindView(R.id.tv_housePhone)
    TextView tv_housePhone;
    //简介
    @BindView(R.id.tv_jianjie)
    TextView tv_jianjie;
    //地段
    @BindView(R.id.tv_diduan)
    TextView tv_diduan;
    //配套
    @BindView(R.id.tv_peitao)
    TextView tv_peitao;

    @BindView(R.id.mpaview)
    MapView mapveiw;

    @BindView(R.id.tv_pic_num)
    TextView tv_pic_num;

    SimpleBackActivity simpleBackActivity;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_houseinfo;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
        simpleBackActivity = (SimpleBackActivity) getActivity();
        view_pager.setAdapter(new MyViewPagerAdapter());
        view_pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tv_pic_num.setText(position + 1 + "/" + pics.length);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData() {
        tv_pic_num.setText("1/" + pics.length);
    }

    @OnClick({R.id.iv_back, R.id.tv_plan})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                simpleBackActivity.onBackPressed();
                break;
            case R.id.tv_plan:
                //预约
                UiHelper.shoSimpleBack(mContext, SimpleBackPage.SEEHOUSE, null);
                break;
        }
    }

    /**
     * 自定义 pageAdapter
     */
    class MyViewPagerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return pics.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView iv = new ImageView(getActivity().getApplicationContext());
            iv.setImageResource(pics[position]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            container.addView(iv);
            return iv;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }

}
